import pytest
from py.xml import html


@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
    # 获取钩子方法的调用结果
    out = yield
    # 从钩子方法的调用结果中获取测试报告
    report = out.get_result()

    print('\n用例执行结果', out)
    print('测试报告：%s' % report)
    print('步骤：%s' % report.when)
    print('步骤：%s' % call.when)
    print('nodeid：%s' % report.nodeid)
    print(('运行结果: %s' % report.outcome))
    print('description:%s' % str(item.function.__doc__))
    # extra = getattr(report, "extra", [])
    # extra.append('1')
    # print('测试报告：%s' % report.extra)


def pytest_addoption(parser):
    parser.addoption("--env", action="store", default="prod")


@pytest.fixture(scope="session")
def get_env(request):
    return request.config.getoption('env')